<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>门店订货单</title>
    <link href="../../rs/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../../rs/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="../../rs/plugins/bootstrap_tab/css/bootstrap-table.css" rel="stylesheet">
    <link href="../../rs/css/animate.min.css" rel="stylesheet">
    <link href="../../rs/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="../../rs/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="../../rs/plugins/bootstrap-editable/css/bootstrap-editable.css" rel="stylesheet">
    <?php
      require_once('login.php');
     ?>
    <style>
        .input-daterange{width: 100%;}
        .m-b-xs{
            padding-right: 0px;
            padding-left: 0px;
        }
        .editable-click, a.editable-click, a.editable-click:hover {
            border-bottom: 0px;
        }
        .fixed-table-pagination .page-list{
            display: none;
        }
        .border0{border:0px}
    </style>

</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-content form-inline">

            <div class="col-sm-6 m-b-xs">
                <div class="form-group" id="data_5">

                    <div class="input-daterange input-group" id="datepicker">
                        <input style="height:34px" type="text" class="input-sm form-control" name="start" value="" id="start"/>
                        <span style="background: #E5E6E7;" class="input-group-addon">到</span>
                        <input style="height:34px" type="text" class="input-sm form-control" name="end" value="" id="end"/>
                        <span id="search" style="background: #E5E6E7;cursor:pointer" class="input-group-addon">查找</span>
                    </div>
                </div>

            </div>

            <div class="col-sm-4 m-b-xs"></div>

            <div class="col-sm-1 m-b-xs">
              
            </div>

            <table id="table">
            </table>
            <!-- End Example Card View -->
        </div>
    </div>
</div>
<!-- End Panel Other -->




<script src="../../rs/js/jquery.min.js"></script>
<script src="../../rs/js/bootstrap.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/bootstrap-table.min.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="../../rs/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/bootstrap-table-export.js"></script>
<script src="../../rs/plugins/bootstrap_tab/js/tableExport.js"></script>
<script src="../../rs/js/jquery.cookie.js"></script>
<script src="../../rs/js/common_qj.js"></script>
<script src="../../rs/js/store.min.js"></script>  <!-- 打印面单js -->
<script src="../../rs/plugins/layer/layer.min.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-editable.js"></script>
<script src="../../rs/plugins/bootstrap-editable/js/bootstrap-table-editable.min.js"></script>
<script type="text/javascript">

    var $table = $('#table');

    var sign=URLencode($.cookie('sign'));
//    当天的前一天
//    var rq1=(new Date(new Date()-0 - 1*86400000)).format( 'yyyy-MM-dd')+' 00:00:00';

    var dtn={};
    $(function(){

        var start=(new Date(new Date()-0 - 7*86400000)).format( 'yyyy-MM-dd');
        var end=(new Date()).format( 'yyyy-MM-dd');
        $('#start').val(start);
        $('#end').val(end);
        $('#table').bootstrapTable({
            columns: [
               
                {
                    field: 'orderid',
                    title: '订单单号',

                },
                {
                    field: 'mdtype',
                    title: '类型'
                },                    
                {
                    field: 'operate1',
                    title: '操作员'
                },
                {
                    field: 'operate2',
                    title: '经办人'
                },
               
                 {
                    field: 'notes',
                    title: '备注'
                },
                {
                    field: 'hdxx',
                    align:"center",
                    formatter:"actionFormatter"
                }

            ],

          
            advancedSearch:true,
            clickToSelect:true,
            showExport:true,
            

        });


        
    });

    //    日期插件js开始
    $("#data_5 .input-daterange").datepicker({keyboardNavigation: !1, forceParse: !1, autoclose: !0});
    var config = {
        ".chosen-select": {},
        ".chosen-select-deselect": {allow_single_deselect: !0},
        ".chosen-select-no-single": {disable_search_threshold: 10},
        ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
        ".chosen-select-width": {width: "95%"}
    };
    //    日期插件js结束
//查找数据
    $("#search").click(function(){
        f_s();
    });
    function  f_s(){
        var rq1=$("input[name='start']").val();
        var rq2=$("input[name='end']").val();
        var key=$("input[name='gjc']").val();
        //layer.msg('数据加载中...', {icon: 16, time: 200000, shade: [0.1, 'black']});
        $.ajax({
            type: "post",
            url: G_url+'ormm/query/'+rq1+'/'+rq2,
            data:'sign='+sign,
            dataType: "json",
            success: function (aftdata){

                dtn=aftdata;
                if(aftdata.order.length==0){
                    layer.msg("数据为空！");
                };
                $('#table').bootstrapTable('load',dtn.order);
                layer.closeAll();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });

        
    }
  
   

     function actionFormatter(value, row, index) {
    
      if(row.sfcl=="N"){
          return "<span class='label label-danger'><a style='color:#fff' href='javascript:void(0)' onclick='open_modal("+JSON.stringify(row)+","+index+");'>未处理</a></span>";
      }else if(row.sfcl=="Y"&&row.zt=="0"){
          return "<span class='label label-info'><a style='color:#fff' href='javascript:void(0)' onclick='open_modal("+JSON.stringify(row)+","+index+");'>未审核</a></span>";
      }else if(row.sfcl=="Y"&&row.zt=="1"){
          return "<span class='label label-success'><a style='color:#fff' href='javascript:void(0)' onclick='open_modal("+JSON.stringify(row)+","+index+");'>已审核</a></span>";
          //return "<span class='label label-success'><a style='color:#fff'  >已审核</a></span>";
      }

    }

 

    var djbh;
    var getorderdata; //每一个订单的数据留给save使用时调用
    var order_sfcl;
    function open_modal(data,row) {
        order_sfcl=data.sfcl;
         var orderid=data.orderid;
         djbh=data.orderid;
         var data_detail;
         //数据
          $.ajax({
            type: "post",
            url: G_url+'ormm/cldhd/'+orderid,
            data:'sign='+sign,
            dataType: "json",
            success: function (result){
                getorderdata=result;
                data_detail=result.detail;
                
   
         //页面层
         layer.open({
             title: ['订货单详情'],
             type: 1,
             offset: 'rb',
             shift: 'left',
             area: ['60%', '100%'], //宽高
             shadeClose: true,
           content: '<div style="padding: 10px 30px 10px 30px"> <div class="row" style="padding:8px 0px 8px 0px "><div class="col-sm-4"><div class="input-group "><span class="input-group-btn"><button style="height:34px;background-color: #FFF;border: 1px solid #e5e6e7;font-size: 14px;margin-left:-1px" type="button" class="btn btn-sm ">仓库</button></span><select class="form-control" id="m_ck"></select></div></div><div class="col-sm-4 m-b-xs"></div><div class="col-sm-4 m-b-xs"><div id="toolbar1"><button onclick="save_sh()" id="sh_order" style="float:right;margin-left:5px" class="btn btn-danger"><i class="glyphicon glyphicon-zoom-in"></i> 审核</button><button onclick="save_do()" style="float:right;margin-right:5px" class="btn btn-success"><i class="glyphicon glyphicon-ok"></i> 保存</button></div></div></div>  <table id="table1"></table></div>'
         });
            //给仓库做循环
         $.ajax({
             type: "post",
             url:G_url+'sysg/see',
             data: 'sign=' + sign,
             dataType: "json",
             success: function (result) {
                 layer.closeAll('loading');
                 var ff = result.data;
                 var html1 = '';
                 $.each(ff, function (a, b) {//直接取出json的prolist做each循环.
                     html1 += "<option value='" + b.ShopGroupID + "'>" + b.ShopGroupName + "</option>";//拼接字符串.
                 });
                 $("#m_ck").append(html1);   
                 
            // 获取仓库并赋值
                var ck_val=getorderdata.order.ckbh;
                $("#m_ck").find("option[value="+ck_val+"]").prop("selected",true);
             },
             error: function (XMLHttpRequest, textStatus, errorThrown) {
             }
         });



          
          if(order_sfcl=="N"){
           $('#sh_order').attr("disabled",true);
             }else{
             $('#sh_order').attr("disabled",false);
        }
  

         $('#table1').bootstrapTable('destroy');//删除table表格
         
         $('#table1').bootstrapTable({//重新建立表格
             columns: [
                 {
                     field: 'prmc',
                     title: '商品名称'
                 },
                 {
                     field: 'sl',
                     title: '数量',
                     editable: true,
                 },
                 {
                     field: 'dj',
                     title: '单价',
                     editable: true,
                 },
                  {
                     field: 'bz',
                     title: '备注',
                     editable: true,
                 }
             ],
             shadeClose: true,
             data:data_detail, 

            //当修改数值后执行的保存操作
             onEditableSave: function (field, row, oldValue, $el) {
                 if (field == 'sl') {
                     if (isNaN(row.sl)) {
                         row.sl = oldValue;
                     }if(row.sl==""){
							 row.sl = oldValue;
					}else {
                         row.sl=parseFloat(row.sl).toFixed(2);
                     }
                 }
                 if (field == 'dj') {
                     if (isNaN(row.dj)) {
                         row.dj = oldValue;
                     }if(row.dj==""){
						 row.dj = oldValue;
						}else {
                         row.dj=parseFloat(row.dj).toFixed(2);
                     }
                 }
                 $('#table1').bootstrapTable('load', result.detail);
                // return true;
             }


         });
          
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
     }
 
//保存
 function save_do(){
                 
           
              var ckbh=$("#m_ck option:selected").val();
           
             layer.confirm('确定要保存吗？', {
                 title: [''],
                 btn: ['确定', '取消'] //按钮
             }, function (index) {
                 layer.msg('数据保存中...', {icon: 16, time: 200000, shade: [0.1, 'black']});
                 var bz=$('#ddbz').val();
                 var data=[{
                     "ckbh":ckbh,
                     "djbh":djbh,
                     djje:'0',
                     bz:""
                 }];
                 var data1=$('#table1').bootstrapTable('getData');				 
                 var save={};
                 save.order=data;
                 save.detail=data1;
                //save.sign=sign1;
                 $.ajax({
                     type: "post",
                     url: G_url+'stino/save2/'+djbh+"?sign="+sign,
                     data:JSON.stringify(save),
                     dataType: "json",
                     success: function(res) {
                         if (res.ok){
                             layer.msg(res.msg);
                             layer.close(index);
                              f_s(); 
                         } else {
                             layer.msg(res.msg);
                         }
                     },
                     error: function (XMLHttpRequest, textStatus, errorThrown) {
                         layer.msg('数据保存失败', {time: 1000});
                     }
                 });
                 layer.close(index);
             }, function (index) {
                 layer.close(index);
             });

     }



     //审核
      function save_sh(){ 

         layer.confirm('确定提交审核吗？', {
             title: [''],
             btn: ['确定', '取消'] //按钮
         }, function (index) {
             //sh();
             layer.msg('数据提交中...', {icon: 16, time: 200000, shade: [0.1, 'black']});
             $.ajax({
                 async: false,
                 type: "post",
                 url: G_url+'stino/sh/'+djbh,
                 data:'sign=' + sign,
                 dataType: "json",
                 success: function(res) {
                     if (res.ok){
                         layer.msg(res.msg);
                        layer.close(index);
                              f_s();
                     } else {
                         layer.msg(res.msg);

                     }
                 },
                 error: function (XMLHttpRequest, textStatus, errorThrown) {
                     layer.msg('审核失败！', {time: 1000});
                 }
             });
             layer.close(index);
         }, function (index) {
             layer.close(index);
         });
     }


</script>
</body>
</html>
